gusucode.com > ASP+ACCESS在线手机销售系统(论文+源代码+答辩PPT) > ASP+ACCESS在线手机销售系统(论文+源代码+答辩PPT)\9)ASP 在线手机销售系统\HandsetPro\handset\pySucInfo.asp

    <%

dim orderID	'此为订单编号,页面级变量
Sub SubmitOrder()
	dim cmdObj, rsObj, strSQL
	'防止反复刷新此页
	if Session("productList") = "" then 
		Response.Clear()
		Server.Transfer "default.asp"
	end if
		
	'创建对象
	Set cmdObj  =  Server.CreateObject("ADODB.Command")
	Set rsObj  =  Server.CreateObject("ADODB.RecordSet")
	cmdObj.CommandText  =  "SELECT top 1 * FROM OrderList ORDER by id desc"
	cmdObj.CommandType  =  adCmdText
	
	Err.Clear()
	On Error Resume Next
	'开始事务,这里使用事务因为向OrderList和向OrderDetail表插入数据必须同时发生
	conn.BeginTrans
	Set cmdObj.ActiveConnection  =  conn
	'打开记录集
	rsObj.Open cmdObj, , adOpenStatic, adLockOptimistic
	'向OrderList表中添加数据
	rsObj.AddNew 
	if Session("memberID")<>"" then
		rsObj("memberID")  = Session("memberID")
	else
		rsObj("memberID")  = 0 '非会员
	end if
	rsObj("customerName")  =  Request.Form("customerName")
	rsObj("address")  =  Request.Form("address")
	rsObj("Zipcode")  =   Request.Form("Zipcode")
	rsObj("phone")  =   Request.Form("phone")
	rsObj("email")  =  Request.Form("email")
	rsObj("payment")  =  Request.Form("payment")
	rsObj("remark")  =  Request.Form("remark")
	rsObj.Update
	rsObj.Close
	'寻找刚才添加的记录,以获取OrderList中的编号
	strSQL = "SELECT top 1 * FROM OrderList ORDER by id desc"
	'Response.Write  "aa<br>"
	set rsObj = conn.Execute (strSQL)
	if rsObj.eof or Err then
		Response.Write "bb<br>"
		Response.Write Err.Description 
		'如果有错误发生,则回滚
		conn.RollbackTrans()
		Response.Write "数据库操作失败,请<a href = 'Javascript:window.history.go(-1)'>返回</a>"
		Response.End
	else
		orderID = rsObj("id")
		'Response.Write "cc<br>"
		'Response.Write orderID
	end if
	rsObj.Close()
	
	'向OrderDetail表中添加数据
	dim Sum, productList, quantityArray, productArray, quantity
	dim i

	productList = Session("productList")
	If Len(productList) <>0 Then
		quantityArray  =  Split(Session("quantityList"), ", ")
		productArray  =  Split(Session("productList"), ", ")
		for i = 0 to UBound(productArray)
			strSQL  =  "SELECT * FROM product WHERE id = "&productArray(i)
			rsObj.Open strSQL, conn, adOpenKeyset, adLockReadOnly 
 			if Not rsObj.EOF or err then
				quantity  =  quantityArray(i)
				If quantity <=  0 Then quantity  =  1
				strSQL  =  "INSERT INTO orderDetail (orderID, productID, productName, price,quantity) "  
				strSQL  =  strSQL & "VALUES( "& orderID & ","
				strSQL  =  strSQL & productArray(i) &",'"
				strSQL  =  strSQL & rsObj("name")& "',"
				strSQL  =  strSQL & rsObj("memberPrice")& ","
				strSQL  =  strSQL & quantity&")"
				Conn.Execute(strSQL)
				'更新购买次数
				strSQL = "Update product set buyNum = buyNum+1 WHERE id = "&productArray(i)
				conn.execute (strSQL)
			end if
		next
	else
		Err.Raise  '如果购物车为空,出错
	end if
	if Err then 
		conn.RollbackTrans()
		Response.Write "有错误发生!,订单没有被提交,请重试<br>"
		Response.Write Err.Description 
	else
		'接受事务
		conn.CommitTrans()
		'清空购物车
		Session("productList")  =  ""
		Session("quantityList")  =  ""
	End if
	'释放对象,并将连接放入连接池
	rsObj.Close()
	Set rsObj = Nothing
	Set cmdObj = Nothing
	CloseConn()
	if Err then
		Response.End
	end if
	
end sub

'调用函数提交订单
 SubmitOrder()
%>

      <div align = "center"><br>
        <br>
        <br>
        订单已经递交,订单号为:<b><font size = "7" color = "#FF0000"><%=orderID%></font></b><br>
        <br>
        
        <br>
      </div>
      <TABLE cellSpacing = 0 borderColorDark = rgb(210,232,255) cellPadding = 0 
                  width = "100%" borderColorLight = #aaaaaa border = 1 ID = "Table1">
        <form name = form1 action = payStep3.asp method = post ID = "Form1">
          <tr>
           <td>您的购物车已经被清空,以便再次购物。</td>
          </tr>
          <tr> 
            <td align = "left" nowrap height = "24">收到您的货款后,我们将按您的订单发货,请牢记您的订单号(<%=orderID%>),以便查询。</td>
          </tr>
          <tr> 
            <td  width = 60 nowrap height = "22"> 备注信息</td>
          </tr>
          <tr bgcolor = "#FFDBBF"> 
            <td bgcolor = "rgb(210,232,255)"> 
              <div align = center> 
                <p align = "center"> 
                  <input type = button value = 继续购物 name = Submit22 onClick = "window.location = './';" style = "border: 1px solid #7D85A2; background-color: rgb(210,232,255)" ID = "Button1">
              </div>
            </td>
          </tr>
        </form>
      </table>